const app = getApp();
Page({
  /*** 页面的初始数据*/
  data: {
    reson1:'行程有误',
    reson2:'',
    isShow:true,
    Id:'',
    isCancel:false,
    display:'none', 
    details: [],
    items: [
      { name: 'trip', value: '行程有误',checked:'true'},
      { name: 'num', value: '就餐人数预约错误'},
      { name: 'time', value: '时间预约错误'},
      { name: 'other', value: '其他' },
    ]
  },
  click:function(e) {
    console.log(e)
   let Id = this.data.Id;
   let id = e.currentTarget.id;
      this.setData({
        isCancel:!this.data.isCancel,
        Id:id
      })
  },
  cancel:function () {
    this.setData({
      isCancel: !this.data.isCancel
    })
  },
  sure:function (e) {
    let details = this.data.details;
    let Id = e.currentTarget.dataset.id;
    this.setData({
      isCancel: !this.data.isCancel,
      Id:Id
    })
    let  reson1 = this.data.reson1
    let  reson2 = this.data.reson2
    let  resons = reson1 + reson2
    let that = this
     wx.request({
       url: app.globalData.directory +'api/v2/appointment/cancel',
       method: 'POST',
       data:{
         id:Id,
         reason:resons
       },
       header: {
         'content-type': 'application/json', // 默认值
         'token': wx.getStorageSync('token')
       },
       success:function(res) {
        if (res.data.status == 'ok') {
          wx.showToast({
            title: '取消预约成功',
            icon: 'success',
            duration: 500
          })
          wx.request({
            url: app.globalData.directory + 'api/v2/appointment/getlist',
            header: {
              'content-type': 'application/json', // 默认值
              'token': wx.getStorageSync('token')
            },
            success: function (res) {

              let data = res.data.data

              that.setData({
                details: data,
              })
            }
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 500
          })
          that.setData({
            reson1:'行程有误',
            reson2:''
          })
        }
       }
     })
  },
  radio:function (e) {
     let reson1 = e.detail.value
     this.setData({
       reson1:reson1
     })
  },
  getRes:function(e) {
    let reson2 = e.detail.value
    this.setData({
      reson2:reson2
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.request({
      url: app.globalData.directory + 'api/v2/appointment/getlist',
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        let data = res.data.data;
        that.setData({
          details:data,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let details = this.data.details
    this.setData({
      details:details
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})